<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" href="${contextPath}/admin/stylesheets/common.css?v=${sversion}" />
    <link rel="stylesheet" href="${contextPath}/admin/stylesheets/table.css?v=${sversion}" />
	<script type="text/javascript" src="${contextPath}/ext/jquery/jquery-1.8.1.min.js"></script>
    <script type="text/javascript" src="${contextPath}/admin/ext/layer_v2/layer.js"></script>
    <script type="text/javascript" src="${contextPath}/ext/laydate/laydate.js"></script>
    <script type="text/javascript" src="${contextPath}/admin/ext/jquery/selectbox.js"></script>
    <script type="text/javascript" src="${contextPath}/admin/ext/zw/grid.js?v=${sversion}"></script>
    <script type="text/javascript" src="${contextPath}/admin/javascripts/tool.js?v=${sversion}"></script>
	<script type="text/javascript" src="${contextPath}/admin/javascripts/zcommon.js?v=${sversion}" basepath="${contextPath}" baseinit="ajaxCheckLogin"></script>
</head>
<body>
	<div class="place">
        <span class="label-span">位置：</span>
        <span>数据源配置 - 字段</span>
    </div>
    <div class="body-warp">
        <div class="panel filter-block">
            <form class="form-inline">
                <div class="form-group">
                    <a href="javascript:void(0);" class="btn" id="search-btn"><i class="iconfont">&#xe61b;</i>搜索</a>
                </div>
            </form>
        </div>
        <div class="panel table-tool-bar">
            <a class="btn" href="###" onclick="add()"><i class="add-btn iconfont">&#xe619;</i>新增</a>
            <a class="btn" href="###" onclick="removeItems();"><i class="remove-btn iconfont">&#xe608;</i>删除</a>
            <a class="btn" href="###" onclick="_back();">返回数据源列表</a>
            <a class="btn" href="###" onclick="_genfield();">根据配置的数据库表自动生成</a>
        </div>
        <table class="table" id="table"></table>
    </div>
<script>
    var grid = {};
    $(function() {
        grid = $('#table').grid({
            store: {
				url: '${contextPath}/dbField/list?dbId=${dbId}'
            },
            tool: {
                pagingBar: true
            },
            columns: [
            <#-- 
            	align: 'left'
             -->
            {
                title:'字段名',
                dataIndex:'enName'
            },
            {
                title:'中文名称',
                dataIndex:'chName'
            },
            {
                title:'字段类型',
                dataIndex:'type',
                renderer:function(cd){
                    if(cd == 1){
                        return '数值';
                    }else if(cd == 2){
                        return '字符串';
                    }else if(cd == 3){
                        return '日期';
                    }else{
                        return '';
                    }
                }
            },
            {
                title:'排序号',
                dataIndex:'orders'
            },
            {
                title: '操作',
                dataIndex: 'id',
                renderer: function(cellData, rowData){
                	var result = '';
                	result += '<div style="overflow:hidden;">';
                	result += '<a class="btn btn-primary" href="###" onclick="editItem(\''+cellData+'\');">编辑</a>\n';
                	result += '</div>';
                	return result;
                }
            }]
        });
        
    });
        
    //添加
	function add(){
	   var url = '${contextPath}/dbField/tomodify?dbId=${dbId}';
       layer.open({
           type: 2,
               title: '新增',
               shadeClose: true,
               shade: 0.8,
               area: ['60%', '60%'],
               content: url
       });
	}
	
	//编辑
	function editItem(id){
	   var url = '${contextPath}/dbField/tomodify?dbId=${dbId}&id='+id;
       layer.open({
           type: 2,
               title: '编辑',
               shadeClose: true,
               shade: 0.8,
               area: ['60%', '60%'],
               content: url
       });
	}

	//删除
	function removeItems(){
		var data = grid.getSelectedData('id');
		z_delete2(data, '${contextPath}/dbField/delete?dbId=${dbId}');
	}
	
	function _back(){
	   parent.layer.closeAll();
	}
	
	function _genfield(){
	   if(!confirm("自动生成将会覆盖当前已经设置的字段信息，是否执行？")) return false;
	   var url = '${contextPath}/dbField/genFields?dbId=${dbId}';
	   $.post(url,{},function(data){
            if(1==data.s){
                alert(data.d||"生成成功");
                grid.refresh();
            }else{
                alert(data.d||"生成失败");
            }
        },"json");
	}
	
	$('#search-btn').click(function(){
    	var params = {};
    	grid.load(params);
    });
</script>
</body>
</html>